{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Notes:\n",
    " * run 17 on the TOI targets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/mnt/tess/astronet/checkpoints/extended_25_run_17/1/AstroCNNModel_extended_20210321_154527',\n",
       " '/mnt/tess/astronet/checkpoints/extended_25_run_17/2/AstroCNNModel_extended_20210321_161606',\n",
       " '/mnt/tess/astronet/checkpoints/extended_25_run_17/3/AstroCNNModel_extended_20210321_164646',\n",
       " '/mnt/tess/astronet/checkpoints/extended_25_run_17/4/AstroCNNModel_extended_20210321_171723',\n",
       " '/mnt/tess/astronet/checkpoints/extended_25_run_17/5/AstroCNNModel_extended_20210321_174729',\n",
       " '/mnt/tess/astronet/checkpoints/extended_25_run_17/6/AstroCNNModel_extended_20210321_181710',\n",
       " '/mnt/tess/astronet/checkpoints/extended_25_run_17/7/AstroCNNModel_extended_20210321_184652',\n",
       " '/mnt/tess/astronet/checkpoints/extended_25_run_17/8/AstroCNNModel_extended_20210321_191655',\n",
       " '/mnt/tess/astronet/checkpoints/extended_25_run_17/9/AstroCNNModel_extended_20210321_194703',\n",
       " '/mnt/tess/astronet/checkpoints/extended_25_run_17/10/AstroCNNModel_extended_20210321_201726']"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "chkpt_root = '/mnt/tess/astronet/checkpoints/extended_25_run_17'\n",
    "data_files = '/mnt/tess/astronet/tfrecords-toi/*'\n",
    "tces_file = '/mnt/tess/astronet/tces-toi.csv'\n",
    "\n",
    "nruns = 10\n",
    "\n",
    "def load_ensemble(chkpt_root, nruns):\n",
    "    checkpts = []\n",
    "    for i in range(nruns):\n",
    "        parent = os.path.join(chkpt_root, str(i + 1))\n",
    "        if not os.path.exists(parent):\n",
    "            break\n",
    "        all_dirs = os.listdir(parent)\n",
    "        if not all_dirs:\n",
    "            break\n",
    "        d, = all_dirs\n",
    "        checkpts.append(os.path.join(parent, d))\n",
    "    return checkpts\n",
    "\n",
    "paths = load_ensemble(chkpt_root, nruns)\n",
    "paths"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running model 1\n",
      "Binary prediction threshold: 0.2152499407880693 (orientative)\n",
      "2041 records\n",
      "Running model 2\n",
      "Binary prediction threshold: 0.2152499407880693 (orientative)\n",
      "2041 records\n",
      "Running model 3\n",
      "Binary prediction threshold: 0.2152499407880693 (orientative)\n",
      "2041 records\n",
      "Running model 4\n",
      "Binary prediction threshold: 0.2152499407880693 (orientative)\n",
      "2041 records\n",
      "Running model 5\n",
      "Binary prediction threshold: 0.2152499407880693 (orientative)\n",
      "2041 records\n",
      "Running model 6\n",
      "Binary prediction threshold: 0.2152499407880693 (orientative)\n",
      "2041 records\n",
      "Running model 7\n",
      "Binary prediction threshold: 0.2152499407880693 (orientative)\n",
      "2041 records\n",
      "Running model 8\n",
      "Binary prediction threshold: 0.2152499407880693 (orientative)\n",
      "2041 records\n",
      "Running model 9\n",
      "Binary prediction threshold: 0.2152499407880693 (orientative)\n",
      "2041 records\n",
      "Running model 10\n",
      "Binary prediction threshold: 0.2152499407880693 (orientative)\n",
      "2041 records\n"
     ]
    }
   ],
   "source": [
    "import getpass\n",
    "import os\n",
    "from astronet import predict\n",
    "import tensorflow as tf\n",
    "\n",
    "\n",
    "def run_predictions(path):\n",
    "    predict.FLAGS = predict.parser.parse_args([\n",
    "      '--model_dir', path,\n",
    "      '--data_files', data_files,\n",
    "      '--output_file', '',\n",
    "    ])\n",
    "\n",
    "    return predict.predict()\n",
    "\n",
    "\n",
    "paths = load_ensemble(chkpt_root, nruns)\n",
    "ensemble_preds = []\n",
    "config = None\n",
    "for i, path in enumerate(paths):\n",
    "    print(f'Running model {i + 1}')\n",
    "    preds, config = run_predictions(path)\n",
    "    ensemble_preds.append(preds)\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels = ['disp_E', 'disp_N', 'disp_J', 'disp_S', 'disp_B']\n",
    "\n",
    "col_e = labels.index('disp_E')\n",
    "# thresh = config.hparams.prediction_threshold\n",
    "# thresh = 0.030485098838860747  # From the validation numbers - maximum thrershold for 100% recall\n",
    "thresh = 0.31245827674871207  # Relaxed to match Liang's precision value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "det_preds = ensemble_preds[0]\n",
    "\n",
    "for i, pred in enumerate(ensemble_preds):\n",
    "    tmp = pred[labels]\n",
    "    newl = [l[-1] + str(i) for l in labels]\n",
    "    for l, nl in zip(labels, newl):\n",
    "        tmp[nl] = tmp[l]\n",
    "    tmp = tmp[newl]\n",
    "    det_preds = pd.concat([\n",
    "        det_preds,\n",
    "        tmp\n",
    "    ], axis=1)\n",
    "    \n",
    "final_order = ['tic_id']\n",
    "for i in range(len(ensemble_preds)):\n",
    "    final_order += ['E' + str(i)]\n",
    "for i in range(len(ensemble_preds)):\n",
    "    final_order += ['N' + str(i)]\n",
    "for i in range(len(ensemble_preds)):\n",
    "    final_order += ['J' + str(i)]\n",
    "for i in range(len(ensemble_preds)):\n",
    "    final_order += ['S' + str(i)]\n",
    "for i in range(len(ensemble_preds)):\n",
    "    final_order += ['B' + str(i)]\n",
    "\n",
    "det_preds = det_preds[final_order]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>tic_id</th>\n",
       "      <th>E0</th>\n",
       "      <th>E1</th>\n",
       "      <th>E2</th>\n",
       "      <th>E3</th>\n",
       "      <th>E4</th>\n",
       "      <th>E5</th>\n",
       "      <th>E6</th>\n",
       "      <th>E7</th>\n",
       "      <th>E8</th>\n",
       "      <th>...</th>\n",
       "      <th>B0</th>\n",
       "      <th>B1</th>\n",
       "      <th>B2</th>\n",
       "      <th>B3</th>\n",
       "      <th>B4</th>\n",
       "      <th>B5</th>\n",
       "      <th>B6</th>\n",
       "      <th>B7</th>\n",
       "      <th>B8</th>\n",
       "      <th>B9</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>176860064</td>\n",
       "      <td>0.998947</td>\n",
       "      <td>0.995673</td>\n",
       "      <td>0.987614</td>\n",
       "      <td>0.97779</td>\n",
       "      <td>0.991777</td>\n",
       "      <td>0.997504</td>\n",
       "      <td>0.998031</td>\n",
       "      <td>0.996365</td>\n",
       "      <td>0.995827</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00026</td>\n",
       "      <td>0.000439</td>\n",
       "      <td>0.000777</td>\n",
       "      <td>0.001183</td>\n",
       "      <td>0.000873</td>\n",
       "      <td>0.000383</td>\n",
       "      <td>0.000349</td>\n",
       "      <td>0.000781</td>\n",
       "      <td>0.000391</td>\n",
       "      <td>0.000444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>236887394</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>237086564</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>243185500</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>16920150</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 51 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      tic_id        E0        E1        E2       E3        E4        E5  \\\n",
       "0  176860064  0.998947  0.995673  0.987614  0.97779  0.991777  0.997504   \n",
       "1  236887394  1.000000  1.000000  1.000000  1.00000  1.000000  1.000000   \n",
       "2  237086564  1.000000  1.000000  1.000000  1.00000  1.000000  1.000000   \n",
       "3  243185500  1.000000  1.000000  1.000000  1.00000  1.000000  1.000000   \n",
       "4   16920150  1.000000  1.000000  1.000000  1.00000  1.000000  1.000000   \n",
       "\n",
       "         E6        E7        E8  ...       B0        B1        B2        B3  \\\n",
       "0  0.998031  0.996365  0.995827  ...  0.00026  0.000439  0.000777  0.001183   \n",
       "1  1.000000  1.000000  1.000000  ...  0.00000  0.000000  0.000000  0.000000   \n",
       "2  1.000000  1.000000  1.000000  ...  0.00000  0.000000  0.000000  0.000000   \n",
       "3  1.000000  1.000000  1.000000  ...  0.00000  0.000000  0.000000  0.000000   \n",
       "4  1.000000  1.000000  1.000000  ...  0.00000  0.000000  0.000000  0.000000   \n",
       "\n",
       "         B4        B5        B6        B7        B8        B9  \n",
       "0  0.000873  0.000383  0.000349  0.000781  0.000391  0.000444  \n",
       "1  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "2  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "3  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "4  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "\n",
       "[5 rows x 51 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "det_preds.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# det_preds.to_csv('~/Astronet-Triage/detailed-preds-toi.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "agg_preds = {}\n",
    "tic_ids = {}\n",
    "\n",
    "pred_idx = 0\n",
    "\n",
    "for preds in ensemble_preds:\n",
    "    for row_id in preds.index:\n",
    "        if row_id not in agg_preds:\n",
    "            agg_preds[row_id] = []\n",
    "            tic_ids[row_id] = preds['tic_id'][row_id]\n",
    "\n",
    "        row = preds[preds.index == row_id]\n",
    "        pred_v = row.values[pred_idx]\n",
    "        if len(row.values) > 1:\n",
    "            print(f'Warning: duplicate predictions for {row_id}')\n",
    "        if pred_v[col_e] >= thresh:\n",
    "            agg_preds[row_id].append('disp_E')\n",
    "        else:\n",
    "            masked_v = [v if i != col_e else 0 for i, v in enumerate(pred_v)]\n",
    "            agg_preds[row_id].append(preds.columns[np.argmax(masked_v)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "final_preds = []\n",
    "for row_id in list(agg_preds.keys()):\n",
    "    counts = {l: 0 for l in labels}\n",
    "    for e in agg_preds[row_id]:\n",
    "        counts[e] += 1\n",
    "    maxcount = max(counts.values())\n",
    "    counts.update({\n",
    "        'row_id': row_id,\n",
    "        'tic_id': tic_ids[row_id],\n",
    "        'maxcount': maxcount,\n",
    "    })\n",
    "    final_preds.append(counts)\n",
    "\n",
    "final_preds = pd.DataFrame(final_preds).set_index('tic_id')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>disp_E</th>\n",
       "      <th>disp_N</th>\n",
       "      <th>disp_J</th>\n",
       "      <th>disp_S</th>\n",
       "      <th>disp_B</th>\n",
       "      <th>row_id</th>\n",
       "      <th>maxcount</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>tic_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>176860064</th>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236887394</th>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237086564</th>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>243185500</th>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16920150</th>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           disp_E  disp_N  disp_J  disp_S  disp_B  row_id  maxcount\n",
       "tic_id                                                             \n",
       "176860064      10       0       0       0       0       0        10\n",
       "236887394      10       0       0       0       0       1        10\n",
       "237086564      10       0       0       0       0       2        10\n",
       "243185500      10       0       0       0       0       3        10\n",
       "16920150       10       0       0       0       0       4        10"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "final_preds.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>tic_id</th>\n",
       "      <th>disp_E</th>\n",
       "      <th>disp_N</th>\n",
       "      <th>disp_J</th>\n",
       "      <th>disp_S</th>\n",
       "      <th>disp_B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1144</th>\n",
       "      <td>146261607</td>\n",
       "      <td>0.001933</td>\n",
       "      <td>0.057857</td>\n",
       "      <td>0.985893</td>\n",
       "      <td>0.010260</td>\n",
       "      <td>0.081816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1144</th>\n",
       "      <td>146261607</td>\n",
       "      <td>0.003601</td>\n",
       "      <td>0.071325</td>\n",
       "      <td>0.972887</td>\n",
       "      <td>0.035778</td>\n",
       "      <td>0.008942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1144</th>\n",
       "      <td>146261607</td>\n",
       "      <td>0.002979</td>\n",
       "      <td>0.064766</td>\n",
       "      <td>0.988681</td>\n",
       "      <td>0.006367</td>\n",
       "      <td>0.014174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1144</th>\n",
       "      <td>146261607</td>\n",
       "      <td>0.001370</td>\n",
       "      <td>0.136906</td>\n",
       "      <td>0.992757</td>\n",
       "      <td>0.002493</td>\n",
       "      <td>0.082827</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1144</th>\n",
       "      <td>146261607</td>\n",
       "      <td>0.000294</td>\n",
       "      <td>0.078095</td>\n",
       "      <td>0.998486</td>\n",
       "      <td>0.001020</td>\n",
       "      <td>0.032257</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1144</th>\n",
       "      <td>146261607</td>\n",
       "      <td>0.001926</td>\n",
       "      <td>0.128329</td>\n",
       "      <td>0.987459</td>\n",
       "      <td>0.009631</td>\n",
       "      <td>0.018141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1144</th>\n",
       "      <td>146261607</td>\n",
       "      <td>0.004094</td>\n",
       "      <td>0.108786</td>\n",
       "      <td>0.985708</td>\n",
       "      <td>0.010657</td>\n",
       "      <td>0.015761</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1144</th>\n",
       "      <td>146261607</td>\n",
       "      <td>0.001130</td>\n",
       "      <td>0.058510</td>\n",
       "      <td>0.994949</td>\n",
       "      <td>0.005938</td>\n",
       "      <td>0.010631</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1144</th>\n",
       "      <td>146261607</td>\n",
       "      <td>0.030710</td>\n",
       "      <td>0.154052</td>\n",
       "      <td>0.868153</td>\n",
       "      <td>0.082078</td>\n",
       "      <td>0.028386</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1144</th>\n",
       "      <td>146261607</td>\n",
       "      <td>0.003636</td>\n",
       "      <td>0.109136</td>\n",
       "      <td>0.984633</td>\n",
       "      <td>0.010141</td>\n",
       "      <td>0.045070</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         tic_id    disp_E    disp_N    disp_J    disp_S    disp_B\n",
       "1144  146261607  0.001933  0.057857  0.985893  0.010260  0.081816\n",
       "1144  146261607  0.003601  0.071325  0.972887  0.035778  0.008942\n",
       "1144  146261607  0.002979  0.064766  0.988681  0.006367  0.014174\n",
       "1144  146261607  0.001370  0.136906  0.992757  0.002493  0.082827\n",
       "1144  146261607  0.000294  0.078095  0.998486  0.001020  0.032257\n",
       "1144  146261607  0.001926  0.128329  0.987459  0.009631  0.018141\n",
       "1144  146261607  0.004094  0.108786  0.985708  0.010657  0.015761\n",
       "1144  146261607  0.001130  0.058510  0.994949  0.005938  0.010631\n",
       "1144  146261607  0.030710  0.154052  0.868153  0.082078  0.028386\n",
       "1144  146261607  0.003636  0.109136  0.984633  0.010141  0.045070"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def compare(ensemble_preds, filter):\n",
    "    result = ensemble_preds[0][filter]\n",
    "    for preds in ensemble_preds[1:]:\n",
    "        result = result.append(preds[filter])\n",
    "    return result\n",
    "\n",
    "compare(ensemble_preds, preds.tic_id == 146261607).sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "# final_preds = final_preds.join(\n",
    "#     pd.read_csv(tces_file, header=0, low_memory=False),\n",
    "#     on='row_id',\n",
    "#     how='inner'\n",
    "# )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# final_preds.to_csv('~/Astronet-Triage/preds-toi.csv')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
